#ifndef _BUOLA_MEDIA_FFMPEG_CINPUTCONTEXT_H_
#define _BUOLA_MEDIA_FFMPEG_CINPUTCONTEXT_H_

#include "ffmpeg.h"

#include <blackbox/cstreamin.h>

namespace buola { namespace media { namespace ffmpeg {

class CInputStream;
class CInputVideoStream;
class CInputAudioStream;
    
class CInputContext
{
public:
    CInputContext();

    void Open(blackbox::CStreamIn<uint8_t> &pIn);

    void FindStreams();
    
    void ProcessNextFrame();

    const std::vector<CInputAudioStream*> &AudioStreams()   {   return mAudio;  }
    const std::vector<CInputVideoStream*> &VideoStreams()   {   return mVideo;  }
    
private:
    static int ReadCB(void *pClosure,uint8_t *pBuf,int pSize);
    static int64_t SeekCB(void *pClosure,int64_t pPos,int pWhence);
    
private:
    AVFormatContext *mCtx;
    std::vector<CInputAudioStream*> mAudio;
    std::vector<CInputVideoStream*> mVideo;

    std::map<int,CInputStream*> mStreams;
    
    blackbox::CStreamIn<uint8_t> *mInStream;
    off_t mInOffset;
};

/*namespace ffmpeg*/ } /*namespace media*/ } /*namespace buola*/ }

#endif
